package com.aididi.sort;

/**
 * @Auther: xuzexiang
 * @Date: 2018-11-14 0014 11:58
 * @Description:    选择排序
 *
 */
public class XuanzeDemo {
    public static void main(String[] args) {
        int num[] = {1,4,2,3,69,23,-4,-1,22};
        selectionSort(num);
    }

    public static void selectionSort(int[] num ){
        int len = num.length;
        int minIndex, temp;
        for (int i = 0; i < len - 1; i++) {
            minIndex = i;
            for (int j = i + 1; j < len; j++) {
                if (num[j] < num[minIndex]) {     //寻找最小的数
                    minIndex = j;                 //将最小数的索引保存
                }
            }
            temp = num[i];
            num[i] = num[minIndex];
            num[minIndex] = temp;
    }
        System.out.println("num = " + num);
    }
    public static void Sort(int[] num ){
        for (int i=0;i<num.length;i++){
            System.out.println();
        }
    }

}
